<template>
  <div class="task-list-container">
    <div class="page-header">
      <h1>我的待办</h1>
      <p>您有 {{ pendingProcessInstanceList.length }} 个待处理任务</p>
    </div>

    <div class="task-list">
      <el-scrollbar height="600px">
        <div v-for="task in pendingProcessInstanceList" :key="task.taskId" class="task-item">
          <div class="task-main">
            <h3>{{ task.procDefName }}</h3>
            <div class="task-meta">
              <span class="process-name">{{ task.procDefName }}</span>
              <span class="assignee">发起人: {{ task.startUserName }}</span>
            </div>
            <div class="task-dates">
              <span>创建: {{ task.createTime }}</span>
              <span class="due-date">截止: {{ task.dueDate }}</span>
            </div>
          </div>
          <div class="task-actions">
            <button class="btn-primary btn-sm">
              <i class="fas fa-play"></i>
              处理
            </button>
          </div>
        </div>
      </el-scrollbar>

    </div>
  </div>
</template>

<script lang="ts" setup>

import {ref, onMounted} from "vue";
import {isLoading} from "@/views/workflow/index";
import {getTodoList} from "@/api/workflow/taskHandle";
import {getUserInfo} from "@/utils/system";
import {message} from "@/utils/ElmessasgeUtils";


const pendingProcessInstanceList = ref<[any]>([{}])

async function updateTodoList() {
  isLoading.value = true;
  await getTodoList({userId: getUserInfo().userId}).then(res => {
    if (res.data.code === 200) {
      pendingProcessInstanceList.value = res.data.data;
    } else {
      message("获取待处理流程列表失败", "error")
    }
    isLoading.value = false;

  })
}

onMounted(async () => {
  await updateTodoList()
})

</script>

<style scoped>

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 页面头部 */
.page-header {
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: #1E293B;
  margin-bottom: 8px;
}

.page-header p {
  color: #64748B;
}

/* 任务列表 */
.task-list-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.task-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.task-item {
  background: white;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}

.task-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.task-item.completed {
  opacity: 0.8;
}

.task-main {
  flex: 1;
}

.task-main h3 {
  color: #1E293B;
  margin-bottom: 8px;
  font-weight: 600;
}

.task-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.process-name {
  color: #6366F1;
  font-weight: 500;
}

.assignee {
  color: #64748B;
}

.task-dates {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: #94A3B8;
}

.due-date {
  color: #EF4444;
  font-weight: 500;
}

.task-actions {
  display: flex;
  gap: 8px;
}

.btn-primary {
  background: #6366F1;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background: #4F46E5;
  box-shadow: 0 4px 6px rgba(79, 70, 229, 0.2);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.9rem;
}
</style>